<?php
if (!defined("DNREAD")) exit();
global $db,$basepref,$api,$setting;
$bc = '';
$bs = array(
            'col' => array('lang'=>'all_col',
                           'form'=>'text',
                           'value'=>1,
                           'default'=>1),
            'row' => array('lang'=>'who_col_all',
                           'form'=>'text',
                           'value'=>1,
                           'default'=>1),
            'date' => array('lang'=>'all_data',
                            'form'=>'checkbox',
                            'value'=>'yes',
                            'default'=>'yes'),
            'rating' => array('lang'=>'all_rating',
                             'form'=>'checkbox',
                             'value'=>'yes',
                             'default'=>'yes'),
            'sort' => array('lang'=>'all_sorting',
                            'form'=>'select',
                            'value'=>array('photosid'=>'ID','title'=>'all_name','public'=>'all_data','hits'=>'all_hits','comments'=>'menu_comment'),
                            'default'=>'photosid'),
            'order' => array('lang'=>'all_sorting',
                             'form'=>'select',
                             'value'=>array('desc'=>'all_desc','asc'=>'all_acs'),
                             'default'=>'desc'),
            'random' => array('lang'=>'photos_random',
                              'form'=>'checkbox',
                              'value'=>'yes',
                              'default'=>'no')
           );
if (defined('SETTING')) {
    return $bs;
}
if (isset($setting['bsarray']) && is_array($setting['bsarray'])) {
    $bs = $setting['bsarray'];
}
$inq = $db->query("SELECT * FROM ".$basepref."_photos WHERE act='yes' ORDER BY ".(($bs['random'] == 'yes') ? 'MD5(RAND())' : $bs['sort'].' '.$bs['order'])." LIMIT ".$bs['col']);
if ($db->numrows($inq) > 0) {
    $tm->unmanule['date'] = $bs['date'];
    $tm->unmanule['rating'] = ($setting['photosrate'] == 'yes' && $bs['rating'] == 'yes') ? 'yes' : 'no';
    $ins['template'] = $tm->parsein($tm->create('mod/photos/photos.standart'));
    $tm->width = preparse((100 / $bs['row']),THIS_INT);
    $bc.= $tm->tableprint(array(1,2,3),true);
    $nt = 0;
    while ($photos = $db->fetchrow($inq)) {
            $ins['alt'] = ($photos['image_alt']) ? $api->siteuni($photos['image_alt']) : '';
            $ins['img'] = '<img src="'.$setting['site_url'].'/'.$photos['image_thumb'].'" alt="'.$ins['alt'].'" />';
            $ins['cpu'] = ($siteglobal['seourl'] == 1 && $photos['cpu']) ? '&amp;cpu='.$photos['cpu'] : '';
            $ins['image'] = ($ins['img']) ? '<a href="'.$setting['site_url'].'/index.php?dn=photos&amp;to=image&amp;id='.$photos['photosid'].$ins['cpu'].'">'.$ins['img'].'</a>' : '';
            $ins['title'] = '<a href="'.$setting['site_url'].'/index.php?dn=photos&amp;to=image&amp;id='.$photos['photosid'].$ins['cpu'].'">'.$api->siteuni($photos['title']).'</a>';
            if ($tm->unmanule['rating'] == 'yes') {
                $rate = @round($photos['totalrating'] / $photos['rating']);
            	$ins['rating'] = '<img src="'.$setting['site_url'].'/temp/'.$setting['site_temp'].'/images/rating/'.$rate.'.gif" alt="'.$lang['down_rate'].' : '.(($rate == 0) ? $lang['all_no'] : $lang['down_rate_'.$rate.'']).'" />';
            } else {
            	$ins['rating'] = '';
            }
            $bc.= $tm->parse(
            array(
            'imgtitle'=>$ins['title'],
            'imgpublic'=>$api->sitetime($photos['public']),
            'image'=>$ins['image'],
            'rating'=>$ins['rating']
            ),
            $ins['template']);
            $nt++;
            if ($nt < $bs['row']) {
            	$bc.= $tm->tableprint(array(4,3),true);
            }
            if ($nt == $bs['row']) {
            	$nt = 0;
            	$bc.= $tm->tableprint(array(4,5,2,3),true);
            }
    }
    $bc.= $tm->tableprint(array(4,5,6),true);
}
return $api->siteuni($bc);
?>
